<%@page import="routeEntity.Route" %>
<%@page import="java.util.List" %>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="bootstrap-3.3.7-dist/css/bootstrap.css">
    <script src="jQuery/jquery-3.3.1.js"></script>
    <script src="bootstrap-3.3.7-dist/js/bootstrap.js"></script>
    <link rel="stylesheet" href="css/queryBook.css">
    <script type="text/javascript">

        function submit_sure(data) {
            var gnl = confirm("确定支付" + data + "元！");
            if (gnl === true) {
                return true;
            } else {
                return false;
            }
        }

        function book() {
            $.ajax({
                type: "POST",
                url: "QueryBook",
                data: $('#bookForm').serialize(),
                success: function (data) {
                    if (data === "true") {
                        window.location.href = 'myTicket.jsp';
                    } else if (data === "noSeat") {
                        alert("本次列车余票不足！！！");
                    } else if (data === "noMoney") {
                        alert("请查看个人信息的账户余额是否充足！！！");
                    } else {
                        alert("请先到首页登录！！！");
                    }
                }
            })
        }


        function go(num) {
            document.getElementById("cp").value = num;
            document.spform.submit();	// 表单提交
        }
    </script>
    <title></title>
</head>
<body>
<%!

    public static final String URL = "queryBook.jsp";

%>
<div class="snow">
    <div class="container">
        <!--logo导航开始-->
        <div class="head">
            <a class="ht"><img src="images/logo.jpg"/></a>
            <div class="hs">
            <span><button type="button" class="btn btn-default btn-lg">
                            <a href="#"><span class="glyphicon glyphicon-user"></span></a>
                            </button>
                <button id="hb" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">${sessionScope.user.getUname()}</button>
            </span>
            </div>
        </div>
        <!--logo导航结束-->
        <!--导航列表开始-->
        <div class="navi-w">
            <div class="navi">
                <ul class="navi">
                    <li>
                        <a href="index.jsp">首页</a>
                    </li>
                    <li class="on">
                        <a href="queryBook.jsp">查询订票</a>
                    </li>
                    <li>
                        <a href="#">出行向导</a>
                    </li>
                    <li>
                        <a href="my.jsp">个人中心</a>
                    </li>
                </ul>
            </div>
        </div>
        <!--导航列表结束-->

        <div class="body"><!--体部div-->

            <div class="chaxun"><!--体部查询div-->
                <form action="QueryRoute" class="form-inline" style="margin: 0 50px">
                    <div class="form-group">
                        <label for="exampleInputName2"><h4 style="color: #ff2c2c;font-size: 20px">起点站:</h4></label>
                        <input type="text" class="form-control input-sm" id="exampleInputName2" style="font-size: 20px" name="fromStation">
                    </div>
                    <div class="form-group">
                        <label for="exampleInputEmail2"><h4 style="color: #f21736;font-size: 20px">终点站: </h4></label>
                        <input type="text" class="form-control input-sm" id="exampleInputEmail2" style="font-size: 20px" name="toStation">
                    </div>


                    <div class="form-group">
                        <label for="exampleInputName2"><h4 style="color: #ff2c2c;font-size: 20px">日期:</h4></label><br>
                        <input style="font-size: 20px;margin-bottom: 5px" type="date" class="form-control input-sm" id="exampleInputName3" name="fromTime">

                        <button style="margin:40px 5px;width: 190px;height: 40px;" type="submit" class="btn btn-lg btn-primary "> 查询</button>
                    </div>
                </form>
            </div><!--体部查询-->

            <div class="container  xinxi" style=" border: 2px solid white; padding-left:0; padding-right: 0;"><!--体部展示信息-->
                <div>
                    <table style="background: rgba(238,234,254,0.5);font-size: 21px;font-family: 楷体;font-weight:400;color: #030802" class="table table-bordered ">
                        <tr>
                            <th>车次ID</th>
                            <th>路线名</th>
                            <th>始发站</th>
                            <th>出站时间</th>
                            <th>终点站</th>
                            <th>到站时间</th>
                            <th>座位数量</th>
                            <th>票价</th>
                            <th>购票</th>
                        </tr>
                        <%
                            List<Route> list;
                            int currentPage = 1;    // 为当前所在的页，默认在第1页
                            int lineSize = 7;        // 每次显示的记录数
                            int allRecorders = 0;    // 表示全部的记录数
                            int pageSize = 10;        // 表示全部的页数（尾页）
                            try {
                                currentPage = Integer.parseInt(request.getParameter("cp"));
                            } catch (Exception e) {
                            }

                            int number = (currentPage - 1) * lineSize;
                            if (session.getAttribute("QueryRouteList") != null) {
                                list = (List) session.getAttribute("QueryRouteList");
                                if (list.size() > 0) {
                                    Route route;
                                    try {
                                        for (int i = number; i < (number + lineSize); i++) {
                                            route = list.get(i);
                        %>
                        <form id="bookForm" onsubmit="return submit_sure( <%=list.get(i).getSeatPrice()%>)">
                            <input type="hidden" name="BookRouteId" value="<%=list.get(i).getRid() %>">
                            <tr>
                                <td><%= route.getRid() %>
                                </td>
                                <td><%= route.getRname() %>
                                </td>
                                <td><%= route.getFromStation() %>
                                </td>
                                <td><%= route.getFromTime() %>
                                </td>
                                <td><%= route.getToStation() %>
                                </td>
                                <td><%= route.getToTime() %>
                                </td>
                                <td><%= route.getSeatNumber() %>
                                </td>
                                <td><%= route.getSeatPrice() %>
                                </td>

                                <td><input type="submit" value="确认" onclick="book()"></td>
                            </tr>
                        </form>
                        <%
                                        }
                                    } catch (Exception e) {
                                    }
                                }
                            }
                        %>
                    </table>
                </div>
                <div style="width: 100%;height: 70px;position: absolute;bottom: -13px;">
                    <form class="form1" name="spform" action="<%=URL%>" method="get" style="font-size: 20px;margin-left: 330px;">
                        <input type="button" value="首页" onclick="go(1)">
                        <input type="button" value="上一页" onclick="go(<%=currentPage-1%>)">
                        <input type="button" value="下一页" onclick="go(<%=currentPage+1%>)">
                        <input type="button" value="尾页" onclick="go(<%=pageSize%>)">

                        跳转到第<select name="selcp" onchange="go(this.value)">
                        <%for (int x = 1; x <= 4; x++) {%>
                        <option value="<%=x%>" <%=x == currentPage ? "SELECTED" : ""%>><%=x%>
                        </option>
                        <%}%>
                    </select>页

                        <input id="cp" type="hidden" name="cp" value="1">
                    </form>
                </div>
            </div><!--体部展示信息-->
        </div><!--体部div-->
        <!--底部-->
        <div class="foot">
            <p>
                <a href="#">关于我们 &nbsp;</a>|
                <a href="#">&nbsp;网站声明 </a>
            </p>
            <p>版权所有©2018 &nbsp; 计科普通一班 &nbsp;第五小组</p>
        </div>
    </div>
</div>
</body>
</html>